home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr47 / ertimer.zip / TIMER.H < prev    next >
C/C++ Source or Header  |  1995-01-01  |  6KB  |  96 lines

  1. /***************************************************************************\
  2. ** TIMING CODE MODULE                                                      **
  3. **=========================================================================**
  4. **  Written by Ethan Rohrer, (c) Nuthing Software, December 4, 1994        **
  5. **                                                                         **
  6. **  Revision History                                                       **
  7. **  ----------------                                                       **
  8. **  Date        Description                                                **
  9. **  ---------   ---------------------------------------------------------  **
  10. **  13 May 94   Initial Release                                            **
  11. **  04 Dec 94   Updated code to conform to current coding standards/style  **
  12. **              Allowed appl. to specify # of timers as param. to TM_Init  **
  13. **              Standardized error handling with function _TM_Error          **
  14. **=========================================================================**
  15. **  This file contains the declarations for publicly available types and   **
  16. **  functions.                                                             **
  17. **=========================================================================**
  18. **  USING THIS MODULE                                                      **
  19. **      Before calling any other timing routine, you must call TM_Init(n), **
  20. **      where  n  specifies the number of timers your application needs.   **
  21. **      It may be a good idea to call TM_Init() in the initialization      **
  22. **      portion of your application.                                       **
  23. **                                                                         **
  24. **      To begin timing an event, make a call to TM_StartTimer(tid),       **
  25. **      where tid is an integer in the range [0..(n-1)] which specifies    **
  26. **      which of the n timers you are starting.                            **
  27. **                                                                         **
  28. **      To compute the duration of the event, just call                    **
  29. **      TM_ElapsedTime(tid), where tid is the same integer used in the     **
  30. **      call to TM_StartTimer().                                           **
  31. **                                                                         **
  32. **      When you are finished with the timing routines, call TM_Close().   **
  33. **      This should fit in nicely with the cleanup section of your         **
  34. **      application.                                                       **
  35. **                                                                         **
  36. **      If your application NEEDS to handle the time computations itself,  **
  37. **      the function TM_ReadTimer(tid) is also available.  This function   **
  38. **      will return the current time (MOD 1 hour, approximately).  I       **
  39. **      discourage use of this function, but discovered that I need it     **
  40. **      for another module/library...                                      **
  41. **                                                                         **
  42. **      EXAMPLES                                                           **
  43. **          A simple delaying routine:                                     **
  44. **          (TM_Init() must be called before this routine!)                **
  45. **              void delay( tTIME duration )                               **
  46. **              {                                                          **
  47. **                  TM_StartTimer(0);                                      **
  48. **                  while (TM_ElapsedTime(0) < duration)                   **
  49. **                      ;                                                  **
  50. **              }                                                          **
  51. **                                                                         **
  52. **          A fixed frame-rate game:                                       **
  53. **              TM_Init(1);                                                **
  54. **              while (player_not_dead)                                    **
  55. **              {                                                          **
  56. **                  TM_StartTimer(0);                                      **
  57. **                  MoveMonsters();                                        **
  58. **                  MovePlayers();                                         **
  59. **                  UpdateDisplay();                                       **
  60. **                  while (TM_ElapsedTime(0) < frame_duration)             **
  61. **                      ;                                                  **
  62. **              }                                                          **
  63. **              TM_Close();                                                **
  64. \***************************************************************************/
  65.  
  66. #ifndef __TIMER_H__
  67. #define __TIMER_H__
  68.  
  69. /*------------------------------ Types ------------------------------------*/
  70.  
  71. /* type used to store time: should be 32-bits */
  72.  
  73. typedef  unsigned long int  tTIME;
  74.  
  75. /*----------------------------- Defines -----------------------------------*/
  76.  
  77. /* maximum number of timers to allow */
  78.  
  79. #define  TM_MAX_TIMERS  1
  80.  
  81. /* just a handy constant */
  82.  
  83. #define  ONE_SECOND  1193200    /* 65536(ticks/cycle) * 18.207(cycles/sec) */
  84.  
  85. /*------------------------- Public Prototypes -----------------------------*/
  86.  
  87. extern  void   TM_Close( );
  88. extern  tTIME  TM_ElapsedTime( );
  89. extern  int    TM_Init( );
  90. extern  tTIME  TM_ReadTime( );
  91. extern  void   TM_StartTimer( );
  92.  
  93. #endif /* __TIMER_H__ */
  94.  
  95.  
  96.